
/**
 * 通知列表
 * Created by KY on 2017/6/23.
 */
define(['ldfw/core','art',
    'text!tpl/notification/list.tpl',
    'text!tpl/notification/row.tpl',
    'comps/ajax',
    'ldfw/helper/formatHelper'],
function (LDFW,artTemplate, tpl, rowTpl, ajax, noticeComp) {
    var View = LDFW.Container.extend({
        tpl: tpl,
        className:'panel',
        initialize: function () {
            this.on('shown', this.loadData)
        },
        events:{
            'click .weui-panel':'gotoDetail'
        },
        rendered: function () {
        },
        loadData: function () {
            const _this = this
            ajax.post('cpliL.3.22').success(function (resp) {
                let noticeList = []
                _.each(resp.result, function (notification) {
                    let noticeStr = notification.notice_variable.replace(/\!/g,'[')
                        .replace(/</g,'{')
                        .replace(/>/g,'}')
                        .replace(/\//g,']')
                    let notice = JSON.parse('{' + noticeStr + '}')
                    notice.notice_type = notification.notice_type
                    notice.cust_name = notification.cust_name
                    notice.notice_date = notification.notice_date
                    noticeList.push(_.extend({},notice,_.pick(notification,'notice_type','cust_name','notice_date','notice_no','confirm_status')))
                })
                _this.renderContent(noticeList)
            })
        },
        renderContent: function (notifications) {
            if(!_.isEmpty(notifications)){
                let html = artTemplate.compile(rowTpl)(notifications)
                this.$el.find('.detail-panel_body').html(html)
            }
        },
        gotoDetail:function(event){
            let notice_no = $(event.currentTarget).attr('notice_no')
            LDFW.navigate('notification/detail/'+notice_no)
        }
    })
    return new View()
})